<template>
    <el-dialog
    title="选择常用流程表达式"
    :close-on-click-modal="false"
    append-to-body
    v-model="visible" draggable>
        <div style="height: calc(600px - 180px);">
            <vxe-toolbar ref="conditionalToolbar" :refresh="{query: refreshList}" custom>
              <template #buttons>
                <el-form  :inline="true" ref="searchForm" :model="searchForm" @keyup.enter="refreshList()" @submit.prevent>
                        <!-- 搜索框-->
                    <el-form-item prop="name">
                            <el-input  prefix-icon="search" v-model="searchForm.name" placeholder="名称" clearable></el-input>
                    </el-form-item>
                </el-form>
              </template>
          </vxe-toolbar>
            <vxe-table
                border
                auto-resize
                resizable
                height="350px"
                :loading="loading"
                size="small"
                ref="conditionalTable"
                show-header-overflow
                show-overflow
                highlight-hover-row
                :menu-config="{}"
                :print-config="{}"
                :import-config="{}"
                :export-config="{}"
                @sort-change="sortChangeHandle"
                :sort-config="{remote:true}"
                :data="dataList"
                :radio-config="{highlight: true}">
                <vxe-column type="seq" width="40"></vxe-column>
                <vxe-column type="radio"  width="60px"></vxe-column>
                <vxe-column  title="名称" field="name" sortable> </vxe-column>
                <vxe-column  title="表达式" field="expression" sortable> </vxe-column>
                <vxe-column  title="备注" field="remarks" sortable> </vxe-column>
            </vxe-table>
            <vxe-pager
              background
              size="small"
              :current-page="tablePage.currentPage"
              :page-size="tablePage.pageSize"
              :total="tablePage.total"
              :page-sizes="[10, 20, 100, 1000, {label: '全量数据', value: 1000000}]"
              :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
              @page-change="currentChangeHandle">
            </vxe-pager>
        </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button  @click="visible = false" icon="circle-close">关闭</el-button>
        <el-button  type="primary"  icon="circle-check" @click="doSubmit()">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
   import conditionService from '@/api/flowable/conditionService'
   export default {
     data () {
       return {
         searchForm: {
           name: ''
         },
          dataList: [],
          tablePage: {
            total: 0,
            currentPage: 1,
            pageSize: 10,
            orders: []
          },
         loading: false,
         visible: false
       }
     },
    mounted () {
      this.$nextTick(() => {
        // 将表格和工具栏进行关联
        const $table = this.$refs.conditionalTable
        const $toolbar = this.$refs.conditionalToolbar
        $table.connect($toolbar)
      })
    },
     methods: {
       show () {
         this.visible = true
         this.refreshList()
       },
      // 获取数据列表
      refreshList () {
        this.loading = true
        conditionService.list({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then((data) => {
          this.dataList = data.records
          this.tablePage.total = data.total
          this.loading = false
        })
      },
      // 当前页
      currentChangeHandle ({ currentPage, pageSize }) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.refreshList()
      },
      // 排序
      sortChangeHandle (column) {
        this.tablePage.orders = []
        if (column.order != null) {
          this.tablePage.orders.push({column: this.$utils.toLine(column.property), asc: column.order === 'asc'})
        }
        this.refreshList()
      },
       doSubmit () {
          let currentRow = this.$refs.conditionalTable.getRadioRecord()
         if (currentRow === null) {
           this.$message.error(`请选择一条表达式!`)
           return
         }
         this.visible = false
         this.$emit('setCondition', currentRow.expression)
       }
     }
   }
</script>
